// Copyright 2012 Google Inc. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package com.google.api.ads.tools.jaxws;

import java.util.Iterator;

import javax.xml.XMLConstants;
import javax.xml.namespace.NamespaceContext;

/**
 * An object which maps namespace prefixes to their URIs. Necessary to get XPath
 * to function correctly. This only maps prefixes necessary to merge the WSDLs
 * of Google's Ads APIs.
 *
 * @author Joseph DiLallo
 */
public class PersonalNamespaceContext implements NamespaceContext {

  private static final String WSDL_PREFIX_URI = "http://schemas.xmlsoap.org/wsdl/";

  public PersonalNamespaceContext() {}

  /**
   * @see NamespaceContext#getNamespaceURI(String)
   */
  public String getNamespaceURI(String prefix) {
    if (prefix == null) {
      throw new IllegalArgumentException("Null namespace prefixes are not allowed.");
    } else if ("wsdl".equals(prefix)) {
      return WSDL_PREFIX_URI;
    } else if ("xsd".equals(prefix)) {
      return XMLConstants.W3C_XML_SCHEMA_NS_URI;
    }
    return XMLConstants.NULL_NS_URI;
  }

  /**
   * This method isn't necessary for XPath processing.
   *
   * @see NamespaceContext#getPrefix(String)
   */
  public String getPrefix(String uri) {
    throw new UnsupportedOperationException();
  }

  /**
   * This method isn't necessary for XPath processing.
   *
   * @see NamespaceContext#getPrefixes(String)
   */
  public Iterator getPrefixes(String uri) {
    throw new UnsupportedOperationException();
  }
}
